<template>
  <view>
    <view class="list">
      <view class="item"
        v-for="item in list"
        :key="item.goods_id"
      >
        <view>{{item.goods_name}}</view>
        <view>
          <text class="btn" @click="changeNumber({
            goods_id: item.goods_id,
            number: item.number - 1
          })">-</text>
          {{item.number}}
          <text class="btn" @click="changeNumber({
            goods_id: item.goods_id,
            number: item.number + 1
          })">+</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  computed: {
    ...mapState('cart', ['list'])
  },
  methods: {
    // minusProd(data) {
    //   // 都应该调用 mutations   
    //   this.$store.commit('cart/changeNumber', data)   
    // },
    // addProd(data) {
    //   // 都应该调用 mutations        
    //   this.$store.commit('cart/changeNumber', data)   
    // }
    ...mapMutations('cart', ['changeNumber']),
    // 跟以下函数等价
    // changeNumber(data) {
    //   this.$store.commit('cart/changeNumber', data)
    // }
  }
}
</script>

<style lang="scss" scoped>

</style>